GBML manual / Drawing

draw_sprite_ripple

Like draw_sprite, but the picture sways left and right as you go down it, like something seen through water. size is how far it sways (1 to 4 pixels each way), length is how many rows from one ripple to the next (16, 32 or 64) and speed is how fast the ripples travel down the screen.

Works differently on Game Boy - The Game Boy sways the lines of the picture by moving its two sprite pieces, like the Advance's ripple; the picture can be 16 pixels wide and 16 tall at most, only one picture is bent at a time, the others are drawn straight.

Works differently on Game Boy Color - The Game Boy Color sways the lines of the picture by moving its two sprite pieces, like the Advance's ripple; the picture can be 16 pixels wide and 16 tall at most, only one picture is bent at a time, the others are drawn straight.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_sprite_ripple(spr, x, y, frame, size, length, speed)

Arguments

NameType
sprsprite
xreal
yreal
frameint
sizeint
lengthint
speedreal

Returns

Nothing.

Description

Draws a sprite that sways left and right as you go down it, like something seen through water or a flag in the wind. It is draw_sprite with a ripple running through the picture.

A real capture - three striped lighthouses side by side: a plain one drawn with draw_sprite, one with a gentle ripple (size 2, length 32, speed 0.5) and one with a tight, fast shimmer (size 4, length 16, speed 1), whose stripes and edges snake from side to sideA real capture - three striped lighthouses side by side: a plain one drawn with draw_sprite, one with a gentle ripple (size 2, length 32, speed 0.5) and one with a tight, fast shimmer (size 4, length 16, speed 1), whose stripes and edges snake from side to side
A real capture - three striped lighthouses side by side: a plain one drawn with draw_sprite, one with a gentle ripple (size 2, length 32, speed 0.5) and one with a tight, fast shimmer (size 4, length 16, speed 1), whose stripes and edges snake from side to side

Left to right: a plain draw_sprite, then the two examples at the bottom of this page. A tall striped lighthouse stands in for the example's small glow sprite, because a wave is much easier to see on something tall - the calls and the numbers are the same. Real pictures from a Game Boy Advance ROM.

x and y are a place in the room, counted from the room's top-left corner, and the sprite is drawn with its origin on that spot, exactly like draw_sprite. It is cached the same way too: call it every frame the sprite should stay on screen, and stop calling it to let it go.

(A sprite can also curve away from you, like text on a barrel: see draw_sprite_3d. It takes two of the same row-by-row effects a ripple takes one of, out of the same pool.)

Three numbers shape the ripple:

The ripples belong to the rows of the screen, not to the sprite. A sprite that moves slides through them, the way a boat moves through waves, and two sprites side by side ripple in step with each other.

A real capture, three pictures of the same scene at frames 4, 24 and 44 - the plain lighthouse never changes, while the ripples in the other two have moved down themA real capture, three pictures of the same scene at frames 4, 24 and 44 - the plain lighthouse never changes, while the ripples in the other two have moved down them
A real capture, three pictures of the same scene at frames 4, 24 and 44 - the plain lighthouse never changes, while the ripples in the other two have moved down them

The same scene at three moments, 20 frames apart. The plain lighthouse on the left is the same every time; look at the wobble in the other two.

A real capture, 16 frames played in a loop - the plain lighthouse stands still while the two rippled ones keep swaying, the waves running down themA real capture, 16 frames played in a loop - the plain lighthouse stands still while the two rippled ones keep swaying, the waves running down them
A real capture, 16 frames played in a loop - the plain lighthouse stands still while the two rippled ones keep swaying, the waves running down them

The same thing playing. This picture is an animated PNG: your browser plays it by itself. A viewer that cannot animate shows only the first frame, which is already the whole comparison.

It only moves the picture sideways. It does not turn it, scale it or blur it, and it is only for a sprite you draw with this call - not for an object's own sprite when it draws itself.

What it costs

A rippling sprite uses one of the 8 row-by-row effects the console has, and no matrix. A room change keeps two of the eight for itself, so there are six left for you: six rippling sprites at once, or fewer if a draw_text_3d line or a draw_sprite_3d sprite is using two of them, or a sky from screen_backdrop is using one: they all share the same six, and the game counts them together, so a room change always has its two. One sprite is one sprite, so a title wider than 64 pixels is several sprites and uses several of the six.

Ask for more than there is and the game stops, in a development build, with a message that names every call holding a slot - they are numbered from 0 in the order they are written in an object's event - and every sky that is holding one too. The sprite has already been drawn plain when it stops, and a release build simply shows it plain. The ripple never fails to appear: you are told.

The ripple tables live in the cartridge, not in memory - about 9 KB, and only in a game that calls this.

Example

draw_sprite_ripple(spr_doc_glow, x, y, 0, 2, 32, 0.5);

The glow, swaying 2 pixels each way in ripples 32 rows long, with the ripples drifting down the screen at half a row a frame.

var wobble = 4;

if (btn_held(BTN_B)) { wobble = 0; }

draw_sprite_ripple(spr_doc_glow, x, y, 0, wobble, 16, 1);

A tight, fast shimmer that stops while B is held, because a size of 0 is just a plain sprite.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the call keeps being made, and no matrix. A room transition keeps two of the eight for itself, so at most six rippling sprites fit on screen (fewer if a 3D text or a 3D sprite is also using two of them). Asking for more than there is stops the game with a message that names every call holding a slot (a release build, which has no such stop, draws the extra ones plain). size 0 draws a plain sprite and costs nothing. length is rounded to the nearest of 16, 32 and 64. The ripples are fixed to the rows of the SCREEN, not to the sprite, so a sprite that moves slides through them, and two sprites side by side ripple in step. A negative speed sends the ripples up; 0 holds them still. One rippling sprite is one sprite, so a title wider than 64 pixels needs several - and several slots.

See also: draw_spritedraw_sprite_scaleddraw_text_3d